<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="搜索" prop="keyword">
        <el-input v-model="queryParams.keyword" placeholder="请输入业务应用名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- 
          <el-select v-model="form.dataproductPriceList[index].userId" placeholder="请选择">
            <el-option v-for="(item,index) in AllUserInfoList" :key="index" :label="item.nickName" :value="item.userId" />
          </el-select>
       -->
      <el-form-item label="用户名" prop="userId">
        <el-select
          v-model="queryParams.userId"
          placeholder="请选择用户"
          clearable
          @keyup.enter.native="handleQuery"
        > 
        <el-option v-for="(item,index) in AllUserInfoList" :key="index" :label="item.nickName" :value="item.userId" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['ApplicationRecord:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ApplicationRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="序号" align="center" prop="id" /> -->
      <el-table-column type="index" width="50" align="center" label="序号"></el-table-column>
      <!-- <el-table-column label="用户ID" align="center" prop="userId" /> -->
      <el-table-column label="业务应用" align="center" prop="applicationName" />
      <el-table-column label="产品" align="center" prop="productName" />
      <el-table-column label="用户" align="center" prop="userName" />

      <el-table-column label="访问时间" align="center" prop="accessTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.accessTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="INPUT信息" align="center" prop="input" />
      <el-table-column label="RET结果" align="center" prop="result" />
      <el-table-column label="DATA/URL信息" align="center" prop="data" />
      <el-table-column label="共享TYPE信息" align="center" prop="type" />
      <el-table-column label="记录数" align="center" prop="records" />
      <el-table-column label="字节数" align="center" prop="bytes" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click="handleUpdate(scope.row)" v-hasPermi="['ApplicationRecord:edit']">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改引擎信息信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-col :span="12">
          <el-form-item label="用户名：">{{ form.userName }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="业务应用：">{{ form.applicationName }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品：">{{ form.productName }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="INPUT信息：">{{ form.input }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="RET结果：">{{ form.result }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="DATA/URL信息：">{{ form.data }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="共享TYPE信息：">{{ form.type }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="记录数：">{{ form.records }}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="字节数：">{{ form.bytes }}</el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="访问时间：">{{ form.accessTime }}
            
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="open=false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listApplicationRecord,
  getApplicationRecord,
  delApplicationRecord,
  addApplicationRecord,
  updateApplicationRecord,
} from "@/api/qysj/app/ApplicationRecord.js";
import { listUser } from "@/api/system/user";
export default {
  name: "ApplicationRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 引擎信息信息表格数据
      ApplicationRecordList: [],
      // 用户数据
      AllUserInfoList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        auditId: null,
        startTime: null,
        endTime: null,
        name: null,
        createUserId: null,
        type: null,
        unit: null,
        price: null,
        status: null,
        keyword: null,
        userId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        auditId: [
          { required: true, message: "审核Id不能为空", trigger: "blur" },
        ],
        createUserId: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询引擎信息信息列表 */
    getList() {
      this.loading = true;
      listApplicationRecord(this.queryParams).then((response) => {
        this.ApplicationRecordList = response.rows;
        console.log(this.ApplicationRecordList);
        this.total = response.total;
        this.loading = false;
      });
      listUser(this.queryParams).then((response) => {
        this.AllUserInfoList = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        auditId: null,
        startTime: null,
        endTime: null,
        name: null,
        createUserId: null,
        type: null,
        unit: null,
        price: null,
        remark: null,
        status: "0",
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "业务应用访问记录信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getApplicationRecord(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "业务应用访问记录信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateApplicationRecord(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApplicationRecord(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除编号为"' + ids + '"的数据项？')
        .then(function () {
          return delApplicationRecord(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "applicationRecord/export",
        {
          ...this.queryParams,
        },
        `ApplicationRecord_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
